package com.css.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.css.dao.IEmployeeDAO;
import com.css.vo.Employee;

public class EmployeeDAO extends HibernateDaoSupport implements IEmployeeDAO {

	@Override
	public void save(Employee employee) {
		getHibernateTemplate().save(employee);
	}

	@Override
	public void delete(Employee employee) {
		getHibernateTemplate().delete(employee);
	}

	@Override
	public void update(Employee employee) {
		getHibernateTemplate().update(employee);
	}

	@Override
	public Employee find(String employeeName) {
		@SuppressWarnings("unchecked")
		List<Employee> list = getHibernateTemplate().find(
				"from Employee where EmployeeName = ?", employeeName);
		if (list.size() > 0) {
			return (Employee) list.get(0);
		} else {
			return null;
		}
	}

	@Override
	public List<Employee> findAllEmployee() {
		List<Employee> list = getHibernateTemplate().find("from Employee");
		return list;
	}

	@Override
	public List<Employee> findById(Integer id) {
		List<Employee> list = getHibernateTemplate().find(
				"from Employee where EmployeeId = ?", id);
		return list;
	}

}
